package org.naxx.security.model.impl.expression;

import org.naxx.security.expression.ExpressionTree;
import org.naxx.security.model.expression.VariableDefinition;
import org.naxx.security.util.Assert;

public class VariableDefinitionImpl implements VariableDefinition {

	private String variableId;
	private ExpressionTree expressionTree;
	
	public VariableDefinitionImpl() {
	}

	public VariableDefinitionImpl(String variableId, ExpressionTree expressionTree) {
		Assert.assertNotNullAndHasLenght(variableId, "Illegal variable id '" 
				+ variableId + "'");
		this.variableId = variableId;
		this.expressionTree = expressionTree;
	}

	public String getVariableId() {
		return this.variableId;
	}

	public ExpressionTree getExpressionTree() {
		return this.expressionTree;
	}
	
	public void setVariableId(String variableId) {
		Assert.assertNotNullAndHasLenght(variableId, "Illegal variable id '" 
				+ variableId + "'");
		this.variableId = variableId;
	}

	public void setExpressionTree(ExpressionTree expressionTree) {
		this.expressionTree = expressionTree;
	}
	
	public boolean equals(Object obj) {
		if (this == obj) {
			return true;
		}
		if (obj instanceof VariableDefinition) {
			VariableDefinition rhs = (VariableDefinition) obj;
			return this.variableId.equals(rhs.getVariableId());
		}
		return false;
	}

	public int hashCode() {
		return this.variableId.hashCode();
	}
}
